﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StudentStatistics
{
    /// <summary>
    /// StudentAnswerControl.xaml 的交互逻辑
    /// </summary>
    public partial class StudentAnswerControl : UserControl
    {
      
        public ObservableCollection<AnswerAndResult> Items
        {
            get { return (ObservableCollection<AnswerAndResult>)GetValue(IteamsProperty); }
            set { SetValue(IteamsProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Iteams.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IteamsProperty =
            DependencyProperty.Register("Items", typeof(ObservableCollection<AnswerAndResult>), typeof(StudentAnswerControl), new PropertyMetadata(new ObservableCollection<AnswerAndResult>()));

        ObservableCollection<AnswerAndResult> OrderIteams = new ObservableCollection<AnswerAndResult>();

        public StudentData StudentData = null;
        int a = 10;
        public StudentAnswerControl(StudentData studentdate)
            : this()
        {
            this.StudentData = studentdate;

            InitializeComponent();
            for (int i = 0; i < a; i++)
            {
                OrderIteams.Add(new AnswerAndResult() { StudentAnswer = "A", TeacherAnswer = "A", Result = "/StudentStatistics;component/Images/right.png " });
            }
            for (int i = 0; i < a; i++)
            {
                OrderIteams.Add(new AnswerAndResult() { StudentAnswer = "B", TeacherAnswer = "B", Result = "/StudentStatistics;component/Images/right.png " });
            }
            for (int i = 0; i < a; i++)
            {
                OrderIteams.Add(new AnswerAndResult() { StudentAnswer = "C", TeacherAnswer = "C", Result = "/StudentStatistics;component/Images/right.png " });
            }

            SetView(0);

            this.Loaded += StudentAnswerControl_Loaded;
        }

        public StudentAnswerControl()
        {

        }

        void StudentAnswerControl_Loaded(object sender, RoutedEventArgs e)
        {
            SetDefautView();
        }

        AminationHelpers amination = new AminationHelpers();
        private void SetDefautView()
        {
            if (StudentData != null)
            {
                this.ratetext.Text = StudentData.Rate * 100 + "%";
                this.StuedentName.Text = StudentData.Name;
                this.consumptiontimetext.Text = StudentData.ConsumptionTime;
                amination.SetAmination(NewControl, new PropertyPath(Control.WidthProperty), 0d, 1800d);
            }
             
        }

        private void ReturnBtn_Click(object sender, RoutedEventArgs e)
        {
            ResultsMainControl.Instacne.SetMainUI();
        }

        /// <summary>
        /// 当前页数
        /// </summary>
        private int CurrentPage = 0;
        /// <summary>
        /// 每页显示多少数据
        /// </summary>
        public int PageCount = 10;

        private void NextBtn_Click(object sender, RoutedEventArgs e)
        {
            if ((CurrentPage + 1) * PageCount < OrderIteams.Count)
            {
                CurrentPage++;
            }
            SetView(CurrentPage);
        }

        private void FrontBtn_Click(object sender, RoutedEventArgs e)
        {
            if (CurrentPage > 0)
            {
                CurrentPage--;
            }

            SetView(CurrentPage);
        }

        private void SetView(int currentpage)
        {
            questionnumbercontrol.QuestionButtonIteams.Clear();
            int first = (currentpage) * PageCount;
            for (int i = 1; i <= PageCount; i++)
            {
                questionnumbercontrol.QuestionButtonIteams.Add((i + first).ToString());
            }
            this.Items = new ObservableCollection<AnswerAndResult>(OrderIteams.Skip(currentpage * PageCount).Take(PageCount).ToList());

            amination.SetAmination(canvascontrol, new PropertyPath(FrameworkElement.HeightProperty), 0d, 690d);
        }

    }

    public class AnswerAndResult
    {

        private string teacheranswer;

        public string TeacherAnswer
        {
            get { return teacheranswer; }
            set { teacheranswer = value; }
        }

        private string studentanswer;

        public string StudentAnswer
        {
            get { return studentanswer; }
            set { studentanswer = value; }
        }

        private string result;

        public string Result
        {
            get { return result; }
            set { result = value; }
        }



    }




}
